﻿/// <reference path="/Scripts/jquery-1.5.1-vsdoc.js" />
/// <reference path="/Scripts/jquery.validate-vsdoc.js" />
$(document).ready(function () {
    $('form').validate({
        rules: {
            Name: {
                required: true,
                remote: {
                    url: '/Company/Validate',
                    type: 'post',
                    dateType: 'json',
                    data: {
                        'Type': 'Name',
                        'Id': function () {
                            return $('#Id').val();
                        },
                        'Value': function () {
                            return $('#Name').val();
                        }
                    }
                }
            },
            Address: 'required',
            Legal: 'required',
            PhoneOfLegal: 'required',
            Contactor: 'required',
            PhoneOfContactor: 'required',
            ProductNO: {
                required: '#CanProduct:checked',
                remote: {
                    url: '/Company/Validate',
                    type: 'post',
                    dateType: 'json',
                    data: {
                        'Type': 'ProductNO',
                        'Id': function () {
                            return $('#Id').val();
                        },
                        'Value': function () {
                            return $('#ProductNO').val();
                        }
                    }
                }
            },
            InstallNO: {
                required: '#CanIntall:checked',
                remote: {
                    url: '/Company/Validate',
                    type: 'post',
                    dateType: 'json',
                    data: {
                        'Type': 'InstallNO',
                        'Id': function () {
                            return $('#Id').val();
                        },
                        'Value': function () {
                            return $('#InstallNO').val();
                        }
                    }
                }
            },
            LendNO: {
                required: '#CanLend:checked',
                remote: {
                    url: '/Company/Validate',
                    type: 'post',
                    dateType: 'json',
                    data: {
                        'Type': 'LendNO',
                        'Id': function () {
                            return $('#Id').val();
                        },
                        'Value': function () {
                            return $('#LendNO').val();
                        }
                    }
                }
            }
        },
        messages: {
            Name: { required: "请输入机构名称", remote: "该机构已存在" },
            Address: "机构地址不能为空",
            Legal: "法人不能为空",
            PhoneOfLegal: "法人联系方式不能为空",
            Contactor: "联系人不能为空",
            PhoneOfContactor: "联系人联系方式不能为空",
            ProductNO: { required: "生产许可编号不能为空", remote: "该生产许可编号已存在" },
            InstallNO: { required: "安装许可编号不能为空", remote: "该安装许可编号已存在" },
            LendNO: { required: '租赁许可编号不能为空', remote: "该租赁许可编号已存在" }
        }
    });
});